﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1.helper;
using WindowsFormsApp1.model;

namespace WindowsFormsApp1
{
    public partial class TechnologicalProcessForm : Form
    {
        private int iOld = -1;
        public TechnologicalProcessForm()
        {
            InitializeComponent();
            loadJobTechnologicalProcesslListHeader();
            loadlVTechnologicalProcess();
        }
        private void loadlVTechnologicalProcess()
        {
            lVTechnologicalProcess.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            List<ShiGongTianChuangModel> lts = DataHelper.GetInstance().JobList;

            lVTechnologicalProcess.Items.Clear();

            ////将lt数据添加到listView1控件中
            foreach (var item in lts)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.UseItemStyleForSubItems = false;
                lvi.Text = item.JobName;
                lvi.SubItems.Add(item.JobSubjectCompany);
                lvi.SubItems.Add(item.JobAddress);
                //string obj = null;
                int index = 0;
                foreach (var st in item.JobTechnologicalProcess)
                {
                    ListViewItem.ListViewSubItem tep = new ListViewItem.ListViewSubItem();
                    tep.Text = st;
                    tep.BackColor = ColorTranslator.FromHtml(item.JobTProcessColor[index]);
                    //String color = ColorTranslator.ToHtml(colorEdit1.Color);
                    lvi.SubItems.Add(tep);
                    index++;
                }
                //lvi.SubItems.Add(obj.TrimEnd(','));
                lvi.SubItems.Add(item.JobStatTime.ToShortTimeString());
                lvi.SubItems.Add(item.JobTotalTime.ToString());

                this.lVTechnologicalProcess.Items.Add(lvi);
            }
        }
        private void loadJobTechnologicalProcesslListHeader()
        {
            List<JobListHeaderModel> lths = DataHelper.GetInstance().JobTechnologicalProcesslListHeader;
            foreach (var item in lths)
            {
                ColumnHeader ch = new ColumnHeader();
                ch.Text = item.HeaderName;   //设置列标题
                ch.Width = item.Width;    //设置列宽度
                ch.TextAlign = (HorizontalAlignment)item.TextAlign;
                lVTechnologicalProcess.Columns.Add(ch);
            }
            loadlVTechnologicalProcess();
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView listview = (ListView)sender;
            ListViewItem lstrow = listview.GetItemAt(e.X, e.Y);
            System.Windows.Forms.ListViewItem.ListViewSubItem lstcol = lstrow.GetSubItemAt(e.X, e.Y);
            string strText = lstcol.Text;
            try
            {
                if (strText == "作业前登记签认")
                {
                    DialogResult d= MessageBox.Show("2018年12月12日12点45分，在永泰站施工作业", "请值班员认真审核防护员登记内容", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                    if (d == DialogResult.OK)
                    {
                        lstcol.BackColor = Color.LawnGreen;
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void lVTechnologicalProcess_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            //if (lVTechnologicalProcess.SelectedIndices.Count > 0) //若有选中项 
            //{
            //    if (iOld == -1)
            //    {
            //        lVTechnologicalProcess.Items[lVTechnologicalProcess.SelectedIndices[0]].BackColor = Color.White;//Color.FromArgb(49, 106, 197); //设置选中项的背景颜色 
            //        //lVTechnologicalProcess.Items[lVTechnologicalProcess.SelectedIndices[0]].BackColor = Color.White;/
            //        iOld = lVTechnologicalProcess.SelectedIndices[0]; //设置当前选中项索引 
            //    }
            //    else
            //    {
            //        if (lVTechnologicalProcess.SelectedIndices[0] != iOld)
            //        {
            //            lVTechnologicalProcess.Items[lVTechnologicalProcess.SelectedIndices[0]].BackColor = Color.FromArgb(49, 106, 197); //设置选中项的背景颜色 
            //            lVTechnologicalProcess.Items[iOld].BackColor = Color.FromArgb(239, 248, 250); //恢复默认背景色 
            //            iOld = lVTechnologicalProcess.SelectedIndices[0]; //设置当前选中项索引 
            //        }
            //    }
            //}
            //else //若无选中项 
            //{
            //    lVTechnologicalProcess.Items[iOld].BackColor = Color.FromArgb(239, 248, 250); //恢复默认背景色 
            //    iOld = -1; //设置当前处于无选中项状态 
            //}
        }
    }
}
